package darkwindclient.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextArea;
import javax.swing.border.MatteBorder;

import darkwindclient.connection.Connection;

/**
 * @author Jacob Ferm 
 */
public class InputField extends JTextArea implements KeyListener {
	private static final long serialVersionUID = 1L;

	private Connection conn;
	private TextField text;
	private TextField log;

	public InputField(Connection conn, TextField text, TextField log) {
		this.conn = conn;
		this.text = text;
		this.log = log;

		setSize(700, 50);
		setOpaque(true);
		setBackground(Color.BLACK);
		setForeground(Color.WHITE);
		setEditable(true);
		setBorder(new MatteBorder(2, 0, 0, 0, Color.white));
		addKeyListener(this);
		setFont(new Font("Simplified Arabic Fixed", Font.PLAIN, 14));
		requestFocus(true);
	}

	@Override
	public void keyPressed(KeyEvent arg0) {
		if (arg0.getKeyCode() == KeyEvent.VK_ENTER) {
			conn.write(getText());
			text.printCommand(getText());
			log.printCommand(getText());
			setText("");
			arg0.consume();
		}
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
	}

	@Override
	public void keyTyped(KeyEvent arg0) {

	}

}
